/**
 * Created by Administrator on 2017/10/16.
 */
let app = new Vue({
    el:"#message-obj",
    data: {
        resources:[],
        is_read:false
    },
    mounted:function () {
        this.first_page();
        document.querySelector("#page_val").onkeydown = (event)=>{
            let e = event || window.event || arguments.callee.caller.arguments[0];
            if(e && e.keyCode===13){ // enter 键
                let inpVal = document.querySelector("#page_val").value;
                this.getObjList(inpVal,pageSize,this.is_read)
            }
        };
    },
    methods: {
        first_page: function () {
            this.getObjList(1,pageSize,this.is_read)
        },
        last_page:function () {
            if(this.resources.currentPage < this.resources.totalPage){
                this.getObjList(this.resources.totalPage,pageSize,this.is_read)
            }
        },
        pre_page:function () {
            if(this.resources.currentPage > 1){
                this.getObjList(this.resources.currentPage-1,pageSize,this.is_read)
            }
        },
        next_page:function () {
            if(this.resources.currentPage < this.resources.totalPage){
                this.getObjList(this.resources.currentPage+1,pageSize,this.is_read)
            }
        },
        getObjList:function (currentPage,pageSize,is_read) {
            $.get(rootPath+"/message/",{currentPage:currentPage,pageSize:pageSize,is_read}, (res)=> {
                if(res.meta.code === 200){
                    this.resources = res.data;
                }else {
                    this.resources = [];
                    alert("请求失败--"+res.meta.message)
                }
            })
        },
        setReaded:function (e) {
            let id_arr = e.target.getAttribute("id");
            $.get(rootPath+"/message/read",{id_arr:id_arr}, (res)=> {
                if(res.meta.code === 200){
                    this.first_page()
                    setdot()
                }else {
                    alert("请求失败--"+res.meta.message)
                }
            })
        },
        searchByType:function () {
            let message_status = $("#message_status").val();
            this.is_read = message_status;
            this.first_page()
        }
    }
})